/*
 * Copyright 2023-2085 xujin <ceo@itgrail.com>
 *
 * Licensed under the Grail License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://itgrail.com/docs?id=3&catalogId=87
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.itgrail.pilot.infrastructure.security.user;

import lombok.Getter;

import java.util.Arrays;

public enum UserRoleEnum {

    //admin角色
    ADMIN("ADMIN", "管理员"),
    //普通用户角色
    USER("USER", "普通用户"),
    //黑名单用户
    BLACK("BLACK", "黑名单");


    @Getter
    private String role;
    @Getter
    private String desc;

    UserRoleEnum(String role, String desc) {
        this.role = role;
        this.desc = desc;
    }

    public static UserRoleEnum parseToEnum(String role) {
        return Arrays.stream(UserRoleEnum.values())
                .filter(roleEnum -> roleEnum.getRole().equalsIgnoreCase(role))
                .findFirst()
                .orElse(null);
    }

    public static UserRoleEnum parseToEnumByDESC(String desc) {
        return Arrays.stream(UserRoleEnum.values())
                .filter(roleEnum -> roleEnum.getDesc().equals(desc))
                .findFirst()
                .orElse(null);
    }

}
